package common

/*
用于定义公共的常量、公共的方法
*/
import (
	"gitee.com/goddesszz/gocommon/myutil"
	"github.com/bwmarrin/snowflake"
	"github.com/google/uuid"
	"os"
)

/*-------------------------- redis中的key或key前缀 -------------------------------*/

const REDIS_KEY_Msg_AllowReCall_Prefix = "msg-allowRecall:"

const REDIS_KEY_ChatGroup_Hash = "group-members_hash_"

const REDIS_KEY_ChatRelId_Hash = "chatRelId_hash_"

// user的ws最近活跃时间
const REDIS_KEY_USER_LastTime_INDEX_PREFIX = "user-lastTime-index-"

/*-------------------------- 公用属性或方法 -------------------------------*/

// 撤回允许时间（秒）
const ReCallExpiredSeconds = 120

var NodeActivePath = "/node_active"
var NodeName string
var AutoIdNode *snowflake.Node = nil

func init() {
	NodeName, _ = os.Hostname()

	snowflake.Epoch = 1748728800000 //2025-06-01 06:00:00
	AutoIdNode, _ = snowflake.NewNode(int64(myutil.HashCode(NodeName) % 1024))
}

// UuidLow 短小的uuid
func UuidLow() string {
	value, _ := uuid.NewRandom()
	v := value.String()
	return v[len(v)-12:]
}

// ModeStatus 启动模式枚举
type ModeStatus int

const (
	Mode_Single  ModeStatus = 0 // 0-单机启动
	Mode_Cluster ModeStatus = 1 // 1-cluster 集群启动
)

// String 方法使用 switch 语句返回枚举值的名称
func (v ModeStatus) String() string {
	switch v {
	case Mode_Single:
		return "Single"
	case Mode_Cluster:
		return "Cluster"
	default:
		return ""
	}
}
